#include "stdafx.h"
//
//////////////////////////////////////////////////////////////
// audio

CTVStreamSourceAudioPin::CTVStreamSourceAudioPin(HRESULT *phr, CSource *pFilter)
	: CTVStreamSourcePin(NAME("Chaos Filter Audio Pin"), phr, pFilter, true)
{	
}

HRESULT CTVStreamSourceAudioPin::OnThreadStartPlay(void)    
{	
	m_pFilter->SetBaseRef(_I64_MAX);
	m_pFilter->SetRawAudioRef(_I64_MAX);
	//
	return CTVStreamSourcePin::OnThreadStartPlay();
}

HRESULT CTVStreamSourceAudioPin::OnThreadDestroy(void)
{
	m_pFilter->SetRawAudioRef(_I64_MAX);
	return CTVStreamSourcePin::OnThreadDestroy();
}
//
STDMETHODIMP CTVStreamSourceAudioPin::NonDelegatingQueryInterface(REFIID riid, void ** ppv)
{
	return CTVStreamSourcePin::NonDelegatingQueryInterface(riid,ppv);
}
//IMediaSeeking
HRESULT CTVStreamSourceAudioPin::ChangeStart()
{
	//SetCurrTime(0);
	//SetBaseRef(_I64_MAX);
	if (m_pFilter && m_pFilter->m_pComm)
		return NOERROR;
	//
	if (ThreadExists()) 
	{
		// next time round the loop the worker thread will
		// pick up the position change.
		// We need to flush all the existing data - we must do that here
		// as our thread will probably be blocked in GetBuffer otherwise
		DeliverBeginFlush();

		// make sure we have stopped pushing
		Stop();

		// complete the flush
		DeliverEndFlush();

		// restart
		Run();
	}

	return NOERROR;
}
//
HRESULT CTVStreamSourceAudioPin::ChangeStop()
{
	return NOERROR;
}
//
HRESULT CTVStreamSourceAudioPin::ChangeRate()
{
	return NOERROR;
}
//
HRESULT CTVStreamSourceAudioPin::Active(void)
{
	//SetSeekData(m_rtStart + m_llBaseTime);
	return CSourceStream::Active();
	
}

void	CTVStreamSourceAudioPin::RawSync(LONGLONG start)
{
	m_pFilter->SetRawAudioRef(start);
}